<template>
	<el-dialog title="档案鉴定" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="档案标题" prop="title">
				<el-input v-model="form.title" placeholder="档案标题" maxlength="80" clearable></el-input>
			</el-form-item>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="文件数量" prop="fileQuantity">
						<el-input-number v-model="form1.fileQuantity" clearable min="0"></el-input-number>/份
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="文件数量" prop="pages">
						<el-input-number v-model="form1.pages" clearable min="0"></el-input-number>/页
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="采集类型" prop="archivesEnterType">{{form1.archivesEnterTypeName}}</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="档案来源" prop="archivesSource">{{form1.archivesSourceName}}
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="档案摘要" prop="subject">{{form1.subject}}</el-form-item>
			<el-form-item label="登记说明" prop="remark">{{form1.remark}}</el-form-item>
			<el-form-item label="档案文件" prop="attachId">
				<sc-upload-file :apiObj="apiObj"  v-model="fileList" :data="{module:'archives'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form1.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="保存年限" prop="storagePeriod">
						<el-input-number v-model="form.storagePeriod" min="1" clearable></el-input-number>/年
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="档案编号" prop="codeNo">
						<el-input v-model="form.codeNo" placeholder="档案编号" maxlength="40" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="鉴定状态" prop="status">
						<el-radio-group v-model="form.status">
							<el-radio-button label="0">待存档</el-radio-button>
							<el-radio-button label="-1">不存档</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="是否为实物" prop="isKind">
						<el-radio-group v-model="form.isKind">
							<el-radio-button label="0">电子</el-radio-button>
							<el-radio-button label="1">实物</el-radio-button>
							<el-radio-button label="2">并存</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="鉴定时间" prop="identifyTime">
						<el-date-picker v-model="form.identifyTime" placeholder="鉴定时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="鉴定人" prop="identifyUser">
						<select-user-dialog v-model:accountId="form.identifyUser" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="文件格式" prop="extName">
						<sc-select v-model="form.extName" :params="{code:'extName'}" :apiObj="$API.archives.archivesDic.getArchivesDicByCode" clearable multiple filterable  style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="涉密等级" prop="classifiedLevel">
						<sc-select v-model="form.classifiedLevel" :params="{code:'archivesSmLevel'}" :apiObj="$API.archives.archivesDic.getArchivesDicByCode" clearable filterable  style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="借阅权限" prop="borrowingFlag">
						<el-radio-group v-model="form.borrowingFlag">
							<el-radio-button label="0">无权借阅</el-radio-button>
							<el-radio-button label="1">可以借阅</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="查询权限" prop="queryFlag">
						<el-radio-group v-model="form.queryFlag">
							<el-radio-button label="0">无权查询</el-radio-button>
							<el-radio-button label="1">可以查询</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="档案摘要" prop="subject">
				<el-input type="textarea" v-model="form.subject" placeholder="档案摘要" maxlength="380" clearable></el-input>
			</el-form-item>
			<el-form-item label="备注说明" prop="remark">
				<el-input type="textarea" v-model="form.remark" placeholder="备注说明" maxlength="380" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from "@/views/module/attachMenu.vue";
import selectUserDialog from "@/views/module/selectUserDialog.vue";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog,
		AttachMenu,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			fileList:[],
			apiObj:this.$API.file.attach.uploadFile,
			form1: {
				recordId:'',
				title: '',
				archivesEnterTypeName: '',
				archivesSourceName: '',
				fileQuantity: 0,
				pages: 0,
				subject:'',
				remark: '',
				attachId:'',
			},
			form:{
				enterId:'',
				title:'',
				subject:'',
				storagePeriod:1,
				codeNo:'',
				attachId:'',
				status:'0',
				isKind:'0',
				classifiedLevel:'',
				extName:[],
				identifyTime:'',
				identifyUser:'',
				disposalMethod:'',
				fileQuantity:0,
				pages:0,
				borrowingFlag:'0',
				queryFlag:'0',
				remark:''
			},
			rules: {
				title: [
					{required: true, message: '档案标题不能为空', trigger: 'blur'}
				],
				codeNo:[
					{required: true, message: '档案编号不能为空', trigger: 'blur'}
				],
				identifyTime:[
					{required: true, message: '鉴定时间不能为空', trigger: 'blur'}
				],
				identifyUser:[
					{required: true, message: '鉴定人不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.archives.archivesRecord.setArchivesIdentify.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form1.recordId = data.recordId
			this.form.enterId = data.recordId
			this.form1.title = data.title
			this.form.title = data.title;
			this.form1.archivesEnterTypeName = data.archivesEnterTypeName
			this.form1.archivesSourceName = data.archivesSourceName
			this.form1.fileQuantity = data.fileQuantity
			this.form.fileQuantity = data.fileQuantity;
			this.form1.pages = data.pages
			this.form.pages = data.pages;
			this.form1.subject = data.subject
			this.form1.remark = data.remark
			this.form.attachId = data.attachId
		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
